<template>
	<view>
		index
	</view>
</template>

<script>
	import { setToken,getToken } from '@/util/request/storage';
	import { get_user_info } from '@/util/api/api.js';
	
	export default {
		data() {
			return {
				
			}
		},
		onLoad(option) {
			let token_key = 'token';
			
			let token = getToken()
			console.log(token)
			debugger
			// let token = '';

			if(!token){
				debugger
				
				//本地没有
				if(option.token){
					setToken(option.token)
					
					
					debugger
				}else{
					let oauth_url = getApp().globalData.domain + '/index.php/html5/weixin/oauth2_login?backurl='+window.location.protocol+'//'+window.location.host

					debugger
					window.location.href = oauth_url
					return
				}
			}
			
			this.load_page()
		},
		methods: {
			async load_page(){
				let user
				
				if (getApp().globalData.userinfo==undefined) {
					let res = await get_user_info()
					
					user = res.data
					
				}
				
				console.log(user)
				
				if (user.status==0) {
					debugger
					uni.redirectTo({
						url: '/pages/add_user/add_user'
					});
				} else{
					if(user.type==1){
						uni.redirectTo({
							url: '/pages/doc/qt/huanzheliebiao'
						});
					}else if(user.type==2){
						uni.redirectTo({
							url: '/pages/doc/ht/huanzheliebiao'
						});
					}else if(user.type==3){
						uni.redirectTo({
							url: '/pages/yaoshi/yaofang'
						});
					}else if(user.type==4){
						uni.redirectTo({
							url: '/pages/huanzheliebiao/huanzheliebiao'
						});
					}else if(user.type==5){
						uni.redirectTo({
							url: '/pages/admin_index/admin_index'
						});
					}
				}
			},
			goto_yaofang_page(id=0){
				uni.navigateTo({
					url: '../yaofang/yaofang?id='+id
				});
			},
			get_zhenduan_list(curpage=0,listnum=0){
				let that = this
				let data = {
					curpage:curpage,
					listnum:listnum
				}
				
				getApp().http_request({
					url:that.url,
					data:data,
					success(res) {
						if (res.data.code==200) {
							that.yaofang.list.push(...res.data.data.datalist)
							that.yaofang.curpage = res.data.data.pages
							that.yaofang.curpage = res.data.data.total
						} else{
							// that.showToast(res.message)
						}
					}
				})
			},
			get_yaofang_list(curpage=0,listnum=0){
				let that = this
				let data = {
					curpage:curpage,
					listnum:listnum
				}
				
				getApp().http_request({
					url:that.url,
					data:data,
					success(res) {
						if (res.data.code==200) {
							that.yaofang.list.push(...res.data.data.datalist)
							that.yaofang.curpage = res.data.data.pages
							that.yaofang.curpage = res.data.data.total
						} else{
							// that.showToast(res.message)
						}
					}
				})
			},
			showToast(text) {
				this.$refs.uToast.show({
					title: text,
					// url: '/pages/user/index'
				})
			},
		}
	}
</script>

<style>
page{
	background-color: #F5F5F5;
}
.yaofang_area{
	width: 700rpx;
	height: 100rpx;
	line-height: 50rpx;
	margin: 25rpx;
	padding: 25rpx;
	background-color: #fff;
}
</style>